<template>
	<view class="layout">
		<!-- 总资产 -->
		<view class="priceBox">
			<view class="tit">总积分</view>
			<view class="money">{{userInfo.point}}</view>
		</view>
		<!-- 明细 -->
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<view class="listBox">
				<view class="tit">明细</view>
				<!-- 空白页 -->
				<view v-if="rowData.length<1 " class="empty">
					<image src="/static/nodata.jpg" mode="aspectFit"></image>
					<view class="empty-tips">
						暂无相关记录~
					</view>
				</view>
				<view class="list">
					<view class="rows" v-for="(row,index) in rowData" :key='index'>
						<view class="row">
							<view class="rowTit">积分变动</view>
							<view class="price income" v-if="row.type==1">+{{row.point}}</view>
							<view class="price" v-else >-{{row.point}}</view>
						</view>
						<view class="row">
							<view class="info">{{row.remark}}</view>
							<view class="time">{{row.create_time}}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';  
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore,
		},
		data() {
			return {
				rowData:[],
				point:0,
				page:1,
				loaded:false,
				loadingType:'more'
			};
		},
		onLoad() {
			if(!this.hasLogin){
				uni.redirectTo({
					url:'/pages/public/login'
				})
				return false
			}
			
			this.loadData()
		},
		computed: {
			...mapState(['hasLogin','userInfo'])
		},
		methods: {
			loadData:function(e){
				
				if(this.loaded === true){
					//tab切换只有第一次需要加载数据
					return;
				}
				if(this.loadingType === 'loading'){
					//防止重复加载
					return;
				}
				this.loadingType = 'loading';
				
				let that = this;
				let _param = {
					token:this.userInfo.token,
					page:this.page
				};
				this.$api.getUrl(this.$api._api.ApiUserPoint,_param,function(res){
					res.data.map(re=>{
						re.create_time = that.$api.timestampToTime(re.create_time*1000)
					})
					that.rowData = res.data;
					
					if(that.rowData.length > 1){
						that.page += 1;
					}
					
					that.loaded = true;
					//判断是否还有数据， 有改为 more， 没有改为noMore
					if(res.total > that.rowData.length)
						that.loadingType = 'more';
					else
						that.loadingType = 'noMore';
				})
			},
			cashLink:function(e){
				uni.navigateTo({
					url:'../../pages/user/cash/cash'
				})
			},
			recharge:function(e){
				uni.navigateTo({
					url:'../recharge/recharge'
				})
			}
		},
	};
</script>

<style lang="scss">
	// 总资产
	.priceBox{
		margin: 30rpx;background:linear-gradient(to right,#fa436a,#fb03a6);
		padding:60rpx 0;border-radius:20rpx;color:#fff;text-align: center;
		.tit{font-size: 30rpx;}
		.money{font-size:65rpx;font-weight: bold;margin-top:20rpx;}
	}
	// 明细
	.listBox{
		margin: 0 30rpx;
		.tit{font-size:32rpx;border-left:6rpx solid #fa436a;height:35rpx;line-height:35rpx;padding-left:10rpx;margin-bottom:30rpx;}
		.rows{
			background:#fff;margin-bottom: 20rpx;padding:25rpx;border-radius:10rpx;
			.row{
				display: flex;align-items: center;
				.rowTit,.info{flex: 1;}
				.rowTit,.price{font-size: 30rpx;font-weight: bold;}
				.price{color:#fa436a;font-size: 35rpx;}
				.info,.time{font-size:26rpx;color:#999;margin-top:10rpx;}
				.income{color:#19d538;}
			}
		}
	}
	
	/* load-more */
	.uni-load-more {
		display: flex;
		flex-direction: row;
		height: 80rpx;
		align-items: center;
		justify-content: center
	}
	
	.uni-load-more__text {
		font-size: 28rpx;
		color: #999
	}
	
	.uni-load-more__img {
		height: 24px;
		width: 24px;
		margin-right: 10px
	}
	
	.uni-load-more__img>view {
		position: absolute
	}
	
	.uni-load-more__img>view view {
		width: 6px;
		height: 2px;
		border-top-left-radius: 1px;
		border-bottom-left-radius: 1px;
		background: #999;
		position: absolute;
		opacity: .2;
		transform-origin: 50%;
		animation: load 1.56s ease infinite
	}
	
	.uni-load-more__img>view view:nth-child(1) {
		transform: rotate(90deg);
		top: 2px;
		left: 9px
	}
	
	.uni-load-more__img>view view:nth-child(2) {
		transform: rotate(180deg);
		top: 11px;
		right: 0
	}
	
	.uni-load-more__img>view view:nth-child(3) {
		transform: rotate(270deg);
		bottom: 2px;
		left: 9px
	}
	
	.uni-load-more__img>view view:nth-child(4) {
		top: 11px;
		left: 0
	}
	
	.load1,
	.load2,
	.load3 {
		height: 24px;
		width: 24px
	}
	
	.load2 {
		transform: rotate(30deg)
	}
	
	.load3 {
		transform: rotate(60deg)
	}
	
	.load1 view:nth-child(1) {
		animation-delay: 0s
	}
	
	.load2 view:nth-child(1) {
		animation-delay: .13s
	}
	
	.load3 view:nth-child(1) {
		animation-delay: .26s
	}
	
	.load1 view:nth-child(2) {
		animation-delay: .39s
	}
	
	.load2 view:nth-child(2) {
		animation-delay: .52s
	}
	
	.load3 view:nth-child(2) {
		animation-delay: .65s
	}
	
	.load1 view:nth-child(3) {
		animation-delay: .78s
	}
	
	.load2 view:nth-child(3) {
		animation-delay: .91s
	}
	
	.load3 view:nth-child(3) {
		animation-delay: 1.04s
	}
	
	.load1 view:nth-child(4) {
		animation-delay: 1.17s
	}
	
	.load2 view:nth-child(4) {
		animation-delay: 1.3s
	}
	
	.load3 view:nth-child(4) {
		animation-delay: 1.43s
	}
	
	@-webkit-keyframes load {
		0% {
			opacity: 1
		}
	
		100% {
			opacity: .2
		}
	}
	.empty{
		// position:fixed;
		// left: 0;
		// top:0;
		width: 100%;
		// height: 100vh;
		padding:150rpx 0;
		display:flex;
		justify-content: center;
		flex-direction: column;
		align-items:center;
		background: #fff;
		image{
			width: 240rpx;
			height: 160rpx;
			margin-bottom:30rpx;
		}
		.empty-tips{
			display:flex;
			font-size: $font-sm+2rpx;
			color: $font-color-disabled;
			.navigator{
				color: $uni-color-primary;
				margin-left: 16rpx;
			}
		}
	}
</style>
